local _G = GLOBAL
-- 兼容棱镜的幻化机制
local dressup_dd_mod = {
    -- 巨型晗猪草相关
    sw_piggymimosa_oversized = {
        isnoskin = true,
        istallbody = true,
        buildfn = function(self, item, buildskin)
            local itemswap = {}
            if item.components.symbolswapdata ~= nil then
                local swap = item.components.symbolswapdata
                itemswap["swap_body_tall"] = self:GetDressData(
                    buildskin, swap.build, swap.symbol, item.GUID, "swap"
                )
            end
            return itemswap
        end
    },
    sw_piggymimosa_oversized_waxed = {
        isnoskin = true,
        istallbody = true,
        buildfn = function(self, item, buildskin)
            local itemswap = {}
            if item.components.symbolswapdata ~= nil then
                local swap = item.components.symbolswapdata
                itemswap["swap_body_tall"] = self:GetDressData(
                    buildskin, swap.build, swap.symbol, item.GUID, "swap"
                )
            end
            return itemswap
        end
    },
    sw_piggymimosa_oversized_rotten = {
        isnoskin = true,
        istallbody = true,
        buildfn = function(self, item, buildskin)
            local itemswap = {}
            if item.components.symbolswapdata ~= nil then
                local swap = item.components.symbolswapdata
                itemswap["swap_body_tall"] = self:GetDressData(
                    buildskin, swap.build, swap.symbol, item.GUID, "swap"
                )
            end
            return itemswap
        end
    },

    -- 猪猪炮
    sw_pig_cannon = {
        isnoskin = false,
        buildfile = "sw_pig_cannon",
        buildsymbol = "swap_sw_pig_cannon",
    },

    -- 暗影之冕
    sw_shadow_crown = {
        isnoskin = false,
        buildfn = function(self, item, buildskin)
            if self.inst._front == nil then
                if buildskin ~= nil and buildskin == "sw_shadow_crown_skin1" then
                    self.inst._front = SpawnPrefab("sw_shadow_crown_equipped", "sw_shadow_crown_equipped_skin1")
                elseif buildskin ~= nil and buildskin == "sw_shadow_crown_skin2" then
                    self.inst._front = SpawnPrefab("sw_shadow_crown_equipped", "sw_shadow_crown_equipped_skin2")
                else
                    self.inst._front = SpawnPrefab("sw_shadow_crown_equipped")
                end
                self.inst._front:OnActivated(self.inst, true)
                self.inst._front:RemoveComponent("prototyper")
            end
            if self.inst._back == nil then
                if buildskin ~= nil and buildskin == "sw_shadow_crown_skin1" then
                    self.inst._back = SpawnPrefab("sw_shadow_crown_equipped", "sw_shadow_crown_equipped_skin1")
                elseif buildskin ~= nil and buildskin == "sw_shadow_crown_skin2" then
                    self.inst._back = SpawnPrefab("sw_shadow_crown_equipped", "sw_shadow_crown_equipped_skin2")
                else
                    self.inst._back = SpawnPrefab("sw_shadow_crown_equipped")
                end
                self.inst._back:OnActivated(self.inst, false)
                self.inst._back:RemoveComponent("prototyper")
            end
        end,
        unbuildfn = function(self, item)
            if self.inst._front ~= nil then
                self.inst._front:Remove()
                self.inst._front = nil
            end
            if self.inst._back ~= nil then
                self.inst._back:Remove()
                self.inst._back = nil
            end
        end
    }
}
-- 将以上的幻化数据插入全局变量 DRESSUP_DATA_LEGION,来实现兼容化
if _G.rawget(_G, "DRESSUP_DATA_LEGION") then -- 已有变量了(多半是别的模组加的),那就逐一添加数据
    for k, v in pairs(dressup_dd_mod) do
        _G.DRESSUP_DATA_LEGION[k] = v
    end
else -- 没有变量，那就直接赋值即可
    _G.DRESSUP_DATA_LEGION = dressup_dd_mod
end
dressup_dd_mod = nil -- 这么大个临时变量，用完就主动清理了吧
